package com.mjlf.jol;

import org.openjdk.jol.info.ClassLayout;

/**
 * @ClassName JolTest1
 * @auther mjlf
 * @Date 2019/7/16 9:38
 * @Description 性能对比
 */
public class JolTest5 {
    public static A a;

    public static void main(String[] args) {

        a = new A();
        System.out.println("before lock");
        System.out.println(ClassLayout.parseInstance(a).toPrintable());

        Thread t1 = new Thread(){

            @Override
            public void run(){
                synchronized (a){
                    System.out.println("before wait");
                    System.out.println(ClassLayout.parseInstance(a).toPrintable());
                    try {
                        a.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("after wait");
                    System.out.println(ClassLayout.parseInstance(a).toPrintable());
                }
            }
        };

        t1.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (a){
            a.notifyAll();
        }
    }

    public static void sync(){
        synchronized (a){
            System.out.println("lock");
            System.out.println(ClassLayout.parseInstance(a).toPrintable());
        }
    }
}
